#include "SubTexture.h"

namespace k2graphics
{

SubTexture::SubTexture()
{
	srcTexture = NULL;
}

SubTexture::SubTexture(AbstractTexture* rawTex)
{
	srcTexture = rawTex;
}

// if you want to set the scaling and translation manually
void SubTexture::setTS(float ncx, float ncy, float nsx, float nsy)
{
	cx = ncx;
	cy = ncy;
	mx = nsx;
	my = nsy;
}

// if you want to specify a rectangle that (0,0) - (1,1) maps to
void SubTexture::setSubRect(float left, float top, float width, float height)
{
	mx = width;
	my = height;
	cx = left;
	cy = top;
}

GLuint SubTexture::getRawGLTexture(int* params, int numParams)
{
	return srcTexture->getRawGLTexture(params, numParams);
}

GLuint SubTexture::getRawGLTexture()
{
	return srcTexture->getRawGLTexture();
}

void SubTexture::getRawTextureCoordinates(float sx, float sy, float &dx, float &dy)
{
	srcTexture->getRawTextureCoordinates((sx * mx) + cx, (sy * my) + cy, dx, dy);
}

void SubTexture::getRawTextureCoordinates(int* params, int numParams, float sx, float sy, float &dx, float &dy)
{
	srcTexture->getRawTextureCoordinates(params, numParams, (sx * mx) + cx, (sy * my) + cy, dx, dy);
}

int SubTexture::getTextureType()
{
	return SUB_TEXTURE;
}

}